package bpmn.diagram.edit.parts;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.draw2d.GridData;
import org.eclipse.draw2d.GridLayout;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ScalablePolygonShape;
import org.eclipse.draw2d.Shape;
import org.eclipse.draw2d.StackLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPolicy;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.LayoutEditPolicy;
import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
import org.eclipse.gef.requests.CreateRequest;
import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeNodeEditPart;
import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.gef.ui.figures.DefaultSizeNodeFigure;
import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Display;

import bpmn.diagram.edit.policies.DataBasedItemSemanticEditPolicy;
import bpmn.diagram.providers.Bpmn_1_1ElementTypes;

/**
 * @generated
 */
public class DataBasedEditPart extends ShapeNodeEditPart {

	/**
	 * @generated
	 */
	public static final int VISUAL_ID = 3013;

	/**
	 * @generated
	 */
	protected IFigure contentPane;

	/**
	 * @generated
	 */
	protected IFigure primaryShape;

	/**
	 * @generated
	 */
	public DataBasedEditPart(View view) {
		super(view);
	}

	/**
	 * @generated
	 */
	protected void createDefaultEditPolicies() {
		super.createDefaultEditPolicies();
		installEditPolicy(EditPolicyRoles.SEMANTIC_ROLE,
				new DataBasedItemSemanticEditPolicy());
		installEditPolicy(EditPolicy.LAYOUT_ROLE, createLayoutEditPolicy());
		// XXX need an SCR to runtime to have another abstract superclass that would let children add reasonable editpolicies
		// removeEditPolicy(org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles.CONNECTION_HANDLES_ROLE);
	}

	/**
	 * @generated
	 */
	protected LayoutEditPolicy createLayoutEditPolicy() {
		org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy lep = new org.eclipse.gmf.runtime.diagram.ui.editpolicies.LayoutEditPolicy() {

			protected EditPolicy createChildEditPolicy(EditPart child) {
				EditPolicy result = child
						.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
				if (result == null) {
					result = new NonResizableEditPolicy();
				}
				return result;
			}

			protected Command getMoveChildrenCommand(Request request) {
				return null;
			}

			protected Command getCreateCommand(CreateRequest request) {
				return null;
			}
		};
		return lep;
	}

	/**
	 * @generated
	 */
	protected IFigure createNodeShape() {
		return primaryShape = new GatewayDataBasedExclusiveFigure();
	}

	/**
	 * @generated
	 */
	public GatewayDataBasedExclusiveFigure getPrimaryShape() {
		return (GatewayDataBasedExclusiveFigure) primaryShape;
	}

	/**
	 * @generated
	 */
	protected NodeFigure createNodePlate() {
		DefaultSizeNodeFigure result = new DefaultSizeNodeFigure(40, 40);
		return result;
	}

	/**
	 * Creates figure for this edit part.
	 * 
	 * Body of this method does not depend on settings in generation model
	 * so you may safely remove <i>generated</i> tag and modify it.
	 * 
	 * @generated
	 */
	protected NodeFigure createNodeFigure() {
		NodeFigure figure = createNodePlate();
		figure.setLayoutManager(new StackLayout());
		IFigure shape = createNodeShape();
		figure.add(shape);
		contentPane = setupContentPane(shape);
		return figure;
	}

	/**
	 * Default implementation treats passed figure as content pane.
	 * Respects layout one may have set for generated figure.
	 * @param nodeShape instance of generated figure class
	 * @generated
	 */
	protected IFigure setupContentPane(IFigure nodeShape) {
		return nodeShape; // use nodeShape itself as contentPane
	}

	/**
	 * @generated
	 */
	public IFigure getContentPane() {
		if (contentPane != null) {
			return contentPane;
		}
		return super.getContentPane();
	}

	/**
	 * @generated
	 */
	protected void setForegroundColor(Color color) {
		if (primaryShape != null) {
			primaryShape.setForegroundColor(color);
		}
	}

	/**
	 * @generated
	 */
	protected void setBackgroundColor(Color color) {
		if (primaryShape != null) {
			primaryShape.setBackgroundColor(color);
		}
	}

	/**
	 * @generated
	 */
	protected void setLineWidth(int width) {
		if (primaryShape instanceof Shape) {
			((Shape) primaryShape).setLineWidth(width);
		}
	}

	/**
	 * @generated
	 */
	protected void setLineType(int style) {
		if (primaryShape instanceof Shape) {
			((Shape) primaryShape).setLineStyle(style);
		}
	}

	/**
	 * @generated
	 */
	public List<IElementType> getMARelTypesOnSource() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(2);
		types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		types.add(Bpmn_1_1ElementTypes.Association_4002);
		return types;
	}

	/**
	 * @generated
	 */
	public List<IElementType> getMARelTypesOnSourceAndTarget(
			IGraphicalEditPart targetEditPart) {
		LinkedList<IElementType> types = new LinkedList<IElementType>();
		if (targetEditPart instanceof PoolEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof TaskEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Task2EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Task3EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Task4EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Task5EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Task6EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Task7EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Task8EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Task9EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof StartEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof IntermediateEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof EndEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof DataObjectEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof InclusiveEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof ComplexEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof ParallelEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof bpmn.diagram.edit.parts.DataBasedEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof LaneEditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof Lane2EditPart) {
			types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		}
		if (targetEditPart instanceof PoolEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof TaskEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Task2EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Task3EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Task4EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Task5EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Task6EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Task7EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Task8EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Task9EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof StartEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof IntermediateEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof EndEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof DataObjectEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof InclusiveEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof ComplexEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof ParallelEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof bpmn.diagram.edit.parts.DataBasedEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof LaneEditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		if (targetEditPart instanceof Lane2EditPart) {
			types.add(Bpmn_1_1ElementTypes.Association_4002);
		}
		return types;
	}

	/**
	 * @generated
	 */
	public List<IElementType> getMATypesForTarget(IElementType relationshipType) {
		LinkedList<IElementType> types = new LinkedList<IElementType>();
		if (relationshipType == Bpmn_1_1ElementTypes.SequenceFlow_4001) {
			types.add(Bpmn_1_1ElementTypes.Pool_2003);
			types.add(Bpmn_1_1ElementTypes.Task_3002);
			types.add(Bpmn_1_1ElementTypes.Task_3009);
			types.add(Bpmn_1_1ElementTypes.Task_3014);
			types.add(Bpmn_1_1ElementTypes.Task_3015);
			types.add(Bpmn_1_1ElementTypes.Task_3016);
			types.add(Bpmn_1_1ElementTypes.Task_3017);
			types.add(Bpmn_1_1ElementTypes.Task_3018);
			types.add(Bpmn_1_1ElementTypes.Task_3019);
			types.add(Bpmn_1_1ElementTypes.Task_3020);
			types.add(Bpmn_1_1ElementTypes.Start_3003);
			types.add(Bpmn_1_1ElementTypes.Intermediate_3004);
			types.add(Bpmn_1_1ElementTypes.End_3005);
			types.add(Bpmn_1_1ElementTypes.DataObject_3006);
			types.add(Bpmn_1_1ElementTypes.Inclusive_3010);
			types.add(Bpmn_1_1ElementTypes.Complex_3011);
			types.add(Bpmn_1_1ElementTypes.Parallel_3012);
			types.add(Bpmn_1_1ElementTypes.DataBased_3013);
			types.add(Bpmn_1_1ElementTypes.Lane_3007);
			types.add(Bpmn_1_1ElementTypes.Lane_3008);
		} else if (relationshipType == Bpmn_1_1ElementTypes.Association_4002) {
			types.add(Bpmn_1_1ElementTypes.Pool_2003);
			types.add(Bpmn_1_1ElementTypes.Task_3002);
			types.add(Bpmn_1_1ElementTypes.Task_3009);
			types.add(Bpmn_1_1ElementTypes.Task_3014);
			types.add(Bpmn_1_1ElementTypes.Task_3015);
			types.add(Bpmn_1_1ElementTypes.Task_3016);
			types.add(Bpmn_1_1ElementTypes.Task_3017);
			types.add(Bpmn_1_1ElementTypes.Task_3018);
			types.add(Bpmn_1_1ElementTypes.Task_3019);
			types.add(Bpmn_1_1ElementTypes.Task_3020);
			types.add(Bpmn_1_1ElementTypes.Start_3003);
			types.add(Bpmn_1_1ElementTypes.Intermediate_3004);
			types.add(Bpmn_1_1ElementTypes.End_3005);
			types.add(Bpmn_1_1ElementTypes.DataObject_3006);
			types.add(Bpmn_1_1ElementTypes.Inclusive_3010);
			types.add(Bpmn_1_1ElementTypes.Complex_3011);
			types.add(Bpmn_1_1ElementTypes.Parallel_3012);
			types.add(Bpmn_1_1ElementTypes.DataBased_3013);
			types.add(Bpmn_1_1ElementTypes.Lane_3007);
			types.add(Bpmn_1_1ElementTypes.Lane_3008);
		}
		return types;
	}

	/**
	 * @generated
	 */
	public List<IElementType> getMARelTypesOnTarget() {
		ArrayList<IElementType> types = new ArrayList<IElementType>(2);
		types.add(Bpmn_1_1ElementTypes.SequenceFlow_4001);
		types.add(Bpmn_1_1ElementTypes.Association_4002);
		return types;
	}

	/**
	 * @generated
	 */
	public List<IElementType> getMATypesForSource(IElementType relationshipType) {
		LinkedList<IElementType> types = new LinkedList<IElementType>();
		if (relationshipType == Bpmn_1_1ElementTypes.SequenceFlow_4001) {
			types.add(Bpmn_1_1ElementTypes.Pool_2003);
			types.add(Bpmn_1_1ElementTypes.Task_3002);
			types.add(Bpmn_1_1ElementTypes.Task_3009);
			types.add(Bpmn_1_1ElementTypes.Task_3014);
			types.add(Bpmn_1_1ElementTypes.Task_3015);
			types.add(Bpmn_1_1ElementTypes.Task_3016);
			types.add(Bpmn_1_1ElementTypes.Task_3017);
			types.add(Bpmn_1_1ElementTypes.Task_3018);
			types.add(Bpmn_1_1ElementTypes.Task_3019);
			types.add(Bpmn_1_1ElementTypes.Task_3020);
			types.add(Bpmn_1_1ElementTypes.Start_3003);
			types.add(Bpmn_1_1ElementTypes.Intermediate_3004);
			types.add(Bpmn_1_1ElementTypes.End_3005);
			types.add(Bpmn_1_1ElementTypes.DataObject_3006);
			types.add(Bpmn_1_1ElementTypes.Inclusive_3010);
			types.add(Bpmn_1_1ElementTypes.Complex_3011);
			types.add(Bpmn_1_1ElementTypes.Parallel_3012);
			types.add(Bpmn_1_1ElementTypes.DataBased_3013);
			types.add(Bpmn_1_1ElementTypes.Lane_3007);
			types.add(Bpmn_1_1ElementTypes.Lane_3008);
		} else if (relationshipType == Bpmn_1_1ElementTypes.Association_4002) {
			types.add(Bpmn_1_1ElementTypes.Pool_2003);
			types.add(Bpmn_1_1ElementTypes.Task_3002);
			types.add(Bpmn_1_1ElementTypes.Task_3009);
			types.add(Bpmn_1_1ElementTypes.Task_3014);
			types.add(Bpmn_1_1ElementTypes.Task_3015);
			types.add(Bpmn_1_1ElementTypes.Task_3016);
			types.add(Bpmn_1_1ElementTypes.Task_3017);
			types.add(Bpmn_1_1ElementTypes.Task_3018);
			types.add(Bpmn_1_1ElementTypes.Task_3019);
			types.add(Bpmn_1_1ElementTypes.Task_3020);
			types.add(Bpmn_1_1ElementTypes.Start_3003);
			types.add(Bpmn_1_1ElementTypes.Intermediate_3004);
			types.add(Bpmn_1_1ElementTypes.End_3005);
			types.add(Bpmn_1_1ElementTypes.DataObject_3006);
			types.add(Bpmn_1_1ElementTypes.Inclusive_3010);
			types.add(Bpmn_1_1ElementTypes.Complex_3011);
			types.add(Bpmn_1_1ElementTypes.Parallel_3012);
			types.add(Bpmn_1_1ElementTypes.DataBased_3013);
			types.add(Bpmn_1_1ElementTypes.Lane_3007);
			types.add(Bpmn_1_1ElementTypes.Lane_3008);
		}
		return types;
	}

	/**
	 * @generated
	 */
	public class GatewayDataBasedExclusiveFigure extends ScalablePolygonShape {

		/**
		 * @generated
		 */
		private WrappingLabel fFigureGatewayDataBasedExclusivelIcon;

		/**
		 * @generated
		 */
		public GatewayDataBasedExclusiveFigure() {

			GridLayout layoutThis = new GridLayout();
			layoutThis.numColumns = 1;
			layoutThis.makeColumnsEqualWidth = true;
			this.setLayoutManager(layoutThis);

			this.addPoint(new Point(getMapMode().DPtoLP(0), getMapMode()
					.DPtoLP(40)));
			this.addPoint(new Point(getMapMode().DPtoLP(39), getMapMode()
					.DPtoLP(80)));
			this.addPoint(new Point(getMapMode().DPtoLP(79), getMapMode()
					.DPtoLP(40)));
			this.addPoint(new Point(getMapMode().DPtoLP(39), getMapMode()
					.DPtoLP(1)));
			this.setFill(true);
			this.setForegroundColor(THIS_FORE);
			this.setBackgroundColor(THIS_BACK);
			createContents();
		}

		/**
		 * @generated
		 */
		private void createContents() {

			fFigureGatewayDataBasedExclusivelIcon = new WrappingLabel();
			fFigureGatewayDataBasedExclusivelIcon.setText("X");
			fFigureGatewayDataBasedExclusivelIcon
					.setForegroundColor(FFIGUREGATEWAYDATABASEDEXCLUSIVELICON_FORE);

			fFigureGatewayDataBasedExclusivelIcon
					.setFont(FFIGUREGATEWAYDATABASEDEXCLUSIVELICON_FONT);

			GridData constraintFFigureGatewayDataBasedExclusivelIcon = new GridData();
			constraintFFigureGatewayDataBasedExclusivelIcon.verticalAlignment = GridData.CENTER;
			constraintFFigureGatewayDataBasedExclusivelIcon.horizontalAlignment = GridData.CENTER;
			constraintFFigureGatewayDataBasedExclusivelIcon.horizontalIndent = 0;
			constraintFFigureGatewayDataBasedExclusivelIcon.horizontalSpan = 1;
			constraintFFigureGatewayDataBasedExclusivelIcon.verticalSpan = 1;
			constraintFFigureGatewayDataBasedExclusivelIcon.grabExcessHorizontalSpace = true;
			constraintFFigureGatewayDataBasedExclusivelIcon.grabExcessVerticalSpace = true;
			this.add(fFigureGatewayDataBasedExclusivelIcon,
					constraintFFigureGatewayDataBasedExclusivelIcon);

		}

		/**
		 * @generated
		 */
		public WrappingLabel getFigureGatewayDataBasedExclusivelIcon() {
			return fFigureGatewayDataBasedExclusivelIcon;
		}

	}

	/**
	 * @generated
	 */
	static final Color THIS_FORE = new Color(null, 18, 41, 150);

	/**
	 * @generated
	 */
	static final Color THIS_BACK = new Color(null, 162, 176, 244);

	/**
	 * @generated
	 */
	static final Color FFIGUREGATEWAYDATABASEDEXCLUSIVELICON_FORE = new Color(
			null, 129, 18, 194);

	/**
	 * @generated
	 */
	static final Font FFIGUREGATEWAYDATABASEDEXCLUSIVELICON_FONT = new Font(
			Display.getCurrent(), Display.getDefault().getSystemFont()
					.getFontData()[0].getName(), 16, SWT.NORMAL);

}
